<?php
class OrgProductRelation extends CActiveRecord
{
	/**
	 * Returns the static model of the specified AR class.
	 * @return Organizations the static model class
	 */
	public static function model($className=__CLASS__)
	{
		return parent::model($className);
	}

	/**
	 * @return string the associated database table name
	 */
	public function tableName()
	{
		return 'organization_products';
	}
	
	public function rules()
	{
		return array(
			array('organization_ID, product_ID', 'required'),
			array('organization_ID, product_ID', 'unique', 'criteria' => array('select'=>$this->tableName(),
															'condition' => 'organization_ID=:organization_ID and product_ID=:product_ID',
															'params'=>array(':organization_ID'=>$this->organization_ID, ':product_ID'=>$this->product_ID)), 
															),
		);
	}
	
	public function relations()
	{
		return array(
			'product'=>array(self::BELONGS_TO, 'Products', 'product_ID'),
			'organization'=>array(self::BELONGS_TO, 'Organizations', 'organization_ID'),
		);
	}
}
?>
